//
//  CustomCell.m
//  UniversalTableView
//
//  Created by 冷悦 on 16/3/11.
//  Copyright © 2016年 冷悦. All rights reserved.
//

#import "PushActivityCustomCell.h"
#import "PushActivityCustomCellModel.h"
#import "Masonry.h"
#import "UIColor+RandomColor.h"
#import "Macro.h"

@interface PushActivityCustomCell ()

@property (nonatomic ,strong)UIView     *customContentView;

@property (nonatomic ,strong)UILabel    *tagLabel;

@property (nonatomic ,strong)UILabel    *titleLabel;

@property (nonatomic ,strong)UILabel    *dateLabel;

@property (nonatomic ,strong)UIImageView *picture;

@property (nonatomic ,strong)UILabel     *introductionLabel;

@property (nonatomic ,strong)UIButton    *pushButton;

@property (nonatomic ,strong)UIButton    *viewnowButton;

@end

@implementation PushActivityCustomCell

#pragma mark - init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.8941 green:0.902 blue:0.9412 alpha:1.0];
        [self setupConstraint];
    }
    return self;
}
#pragma mark - private
- (void)setupConstraint{
    [self.customContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView.mas_left).offset(TenOffsetViewMargin);
        make.right.bottom.equalTo(self.contentView).offset(-TenOffsetViewMargin);
    }];
    
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.customContentView).offset(TenOffsetViewMargin);
        make.width.equalTo(@40);
        make.height.equalTo(self.tagLabel.mas_width).multipliedBy(1/2.3f);
    }];
     
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(self.tagLabel);
        make.left.equalTo(self.tagLabel.mas_right).offset(TenOffsetViewMargin);
        make.width.lessThanOrEqualTo(self.customContentView.mas_width);
    }];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"clock"]];
    [self.customContentView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tagLabel.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.tagLabel.mas_left);
        make.height.equalTo(self.titleLabel.mas_height);
        make.width.equalTo(imageView.mas_height);
        
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView);
        make.left.equalTo(imageView.mas_right).offset(FiveOffsetViewMargin);
        make.height.equalTo(imageView.mas_height);
    }];
    
    [self.picture mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dateLabel.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.customContentView.mas_left).offset(TenOffsetViewMargin);
        make.right.equalTo(self.customContentView.mas_right).offset(-TenOffsetViewMargin);
        make.height.equalTo(@100);
       
    }];
    
    [self.introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picture.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.picture.mas_left);
        make.right.equalTo(self.picture.mas_right);
        
    }];
    
    [self.pushButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.introductionLabel.mas_bottom).offset(TenOffsetViewMargin);
        make.right.equalTo(self.introductionLabel.mas_right);
        make.width.equalTo(@40);
        make.height.equalTo(@20);
        make.bottom.equalTo(self.customContentView.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    [self.viewnowButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pushButton.mas_top);
        make.left.equalTo(self.introductionLabel.mas_left);
        make.width.equalTo(@80);
        make.height.equalTo(self.pushButton.mas_height);
    }];
    
}


#pragma mark - getters
- (UIView *)customContentView {
    if (!_customContentView) {
        _customContentView = [[UIView alloc]init];
        _customContentView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
        _customContentView.layer.borderWidth = 1.0f;
        _customContentView.layer.borderColor = [UIColor colorWithRed:0.8863 green:0.8902 blue:0.9216 alpha:1.0].CGColor;
        _customContentView.layer.cornerRadius = 5.0f;
        _customContentView.layer.masksToBounds = YES;
        [self.contentView addSubview:_customContentView];
    }
    return _customContentView;
}

- (UILabel *)tagLabel {
    if (!_tagLabel) {
        _tagLabel = [[UILabel alloc]init];
        _tagLabel.backgroundColor = [UIColor clearColor];
        _tagLabel.layer.borderWidth = 1.0f;
        _tagLabel.textAlignment = NSTextAlignmentCenter;
        _tagLabel.layer.cornerRadius = 5.0f;
        _tagLabel.font = sTitle_Font;
        _tagLabel.layer.borderColor = [UIColor colorWithRed:0.4392 green:0.7373 blue:0.6863 alpha:1.0].CGColor;
        _tagLabel.textColor = [UIColor colorWithRed:0.4392 green:0.7373 blue:0.6863 alpha:1.0];
        [self.customContentView addSubview:_tagLabel];
    }
    return _tagLabel;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
//        _titleLabel.backgroundColor = [UIColor randomColor];
        _titleLabel.textColor = kTextColor;
        _titleLabel.font = kTitle_Font;
        [self.customContentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc]init];
//        _dateLabel.backgroundColor = [UIColor randomColor];
        _dateLabel.textColor = [UIColor colorWithRed:0.498 green:0.498 blue:0.498 alpha:1.0];
        _dateLabel.font = sTitle_Font;
        [self.customContentView addSubview:_dateLabel];
    }
    return _dateLabel;
}

- (UIImageView *)picture {
    if (!_picture) {
        _picture = [[UIImageView alloc]init];
        _picture.contentMode = UIViewContentModeScaleAspectFit;
//        _picture.backgroundColor = [UIColor redColor];
        [self.customContentView addSubview:_picture];
    }
    return _picture;
}

- (UILabel *)introductionLabel {
    if (!_introductionLabel) {
        _introductionLabel = [[UILabel alloc]init];
//        _introductionLabel.backgroundColor = [UIColor randomColor];
        _introductionLabel.numberOfLines = 0;
        _introductionLabel.textColor = kTextColor;
//        _introductionLabel.font = sTitle_Font;
        [self.customContentView addSubview:_introductionLabel];
    }
    return _introductionLabel;
}

- (UIButton *)pushButton {
    if (!_pushButton) {
        _pushButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        _pushButton.backgroundColor = [UIColor randomColor];
        [_pushButton setTitleColor:[UIColor colorWithRed:0.9843 green:0.2549 blue:0.2235 alpha:1.0] forState:0];
        [_pushButton setTitle:@"推送" forState:UIControlStateNormal];
        [self.customContentView addSubview:_pushButton];
    }
    return _pushButton;
}

- (UIButton *)viewnowButton {
    if (!_viewnowButton) {
        _viewnowButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        _viewnowButton.backgroundColor = [UIColor randomColor];
        [_viewnowButton setTitleColor:[UIColor blackColor] forState:0];
        [_viewnowButton setTitle:@"立即查看" forState:UIControlStateNormal];
        [self.customContentView addSubview:_viewnowButton];
    }
    return _viewnowButton;
}
#pragma mark - setters
- (void)setModel:(PushActivityCustomCellModel *)model{
    self.tagLabel.text = model.tagName;
    self.titleLabel.text = model.title;
    self.dateLabel.text = @"1232435678980";
    self.picture.image = [UIImage imageNamed:model.iconURL];
    self.introductionLabel.text = model.introduction;
    
}

@end
